package com.seanchenxi.gwt.xmlrpc.client;

/**
 * The Class XmlRpcException.
 */
public class XmlRpcException extends Exception {

	/** The Constant serialVersionUID. */
	private static final long serialVersionUID = -5545229206080349034L;

	/**
	 * The fault code of the exception. For servers based on this library, this
	 * will always be 0. (If there are predefined error codes, they should be in
	 * the XML-RPC spec.)
	 */
	public final int code;

	/**
	 * If the transport was able to catch a remote exception (as is the case, if
	 * the local transport is used or if extensions are enabled and the server
	 * returned a serialized exception), then this field contains the trapped
	 * exception.
	 */
	public final Throwable throwable;

	/**
	 * Creates a new instance with the given error code and error message.
	 * 
	 * @param code
	 *            Error code.
	 * @param message
	 *            Detail message.
	 */
	public XmlRpcException(int code, String message) {
		this(code, message, null);
	}

	/**
	 * Creates a new instance with the given error message and cause.
	 *
	 * @param message Detail message.
	 * @param throwable the throwable
	 */
	public XmlRpcException(String message, Throwable throwable) {
		this(0, message, throwable);
	}

	/**
	 * Creates a new instance with the given error message and error code 0.
	 * 
	 * @param message
	 *            Detail message.
	 */
	public XmlRpcException(String message) {
		this(0, message, null);
	}

	/**
	 * Creates a new instance with the given error code, error message and
	 * cause.
	 *
	 * @param code Error code.
	 * @param message Detail message.
	 * @param throwable the throwable
	 */
	public XmlRpcException(int code, String message, Throwable throwable) {
		super(message);
		this.code = code;
		this.throwable = throwable;
	}

	/* (non-Javadoc)
	 * @see java.lang.Throwable#getCause()
	 */
	public Throwable getCause() {
		return throwable;
	}

	/**
	 * Gets the code.
	 *
	 * @return the code
	 */
	public int getCode() {
		return code;
	}
}
